// CheckView.cpp : implementation file
//

#include "stdafx.h"
#include "TestAnaly.h"
#include "CheckView.h"

#include "MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CCheckView

IMPLEMENT_DYNCREATE(CCheckView, CFormView)

CCheckView::CCheckView()
	: CFormView(CCheckView::IDD)
{
	//{{AFX_DATA_INIT(CCheckView)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT

	m_pWnd0 = NULL;
	m_pWnd1 = NULL;
	m_pWnd2 = NULL;
	m_pWnd3 = NULL;

	m_bInit = FALSE;
}

CCheckView::~CCheckView()
{
	MySafeDelete( m_pWnd0 );
	MySafeDelete( m_pWnd1 );
	MySafeDelete( m_pWnd2 );
	MySafeDelete( m_pWnd3 );
}

void CCheckView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCheckView)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCheckView, CFormView)
	//{{AFX_MSG_MAP(CCheckView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
	ON_WM_CREATE()
	ON_WM_SIZE()
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCheckView diagnostics

#ifdef _DEBUG
void CCheckView::AssertValid() const
{
	CFormView::AssertValid();
}

void CCheckView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CCheckView message handlers
int CCheckView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFormView::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO:  Add your specialized creation code here
    m_pWnd0 = new DlgCheck(this);
	m_pWnd0->Create(DlgCheck::IDD,this);
	m_pWnd0->ShowWindow(SW_SHOW);

	m_pWnd1 = new DlgCheck(this);
	m_pWnd1->Create(DlgCheck::IDD,this);
	m_pWnd1->ShowWindow(SW_SHOW);

	m_pWnd2 = new DlgCheck(this);
	m_pWnd2->Create(DlgCheck::IDD,this);
	m_pWnd2->ShowWindow(SW_SHOW);

	m_pWnd3 = new DlgCheck(this);
	m_pWnd3->Create(DlgCheck::IDD,this);
	m_pWnd3->ShowWindow(SW_SHOW);


	return 0;
}

void CCheckView::OnSize(UINT nType, int cx, int cy)
{
	CFormView::OnSize(nType, cx, cy);

	// TODO: Add your message handler code here
	if( !m_bInit ) return;

	int x,y;
	CRect rt,rtClient;
	GetClientRect(&rtClient);
	//ClientToScreen(&rtClient);

	x = rtClient.right/2;
	y = rtClient.bottom/2;

	rt = rtClient;
	rt.right  = x;
	rt.bottom = y;
	m_pWnd0->MoveWindow(&rt);

	rt = rtClient;
	rt.left   = x;
	rt.bottom = y;
	m_pWnd1->MoveWindow(&rt);

	rt = rtClient;
	rt.top    = y;
	rt.right  = x;
	m_pWnd2->MoveWindow(&rt);

	rt = rtClient;
	rt.top    = y;
	rt.left   = x;
	m_pWnd3->MoveWindow(&rt);
}


int CCheckView::Initialize()
{
	m_bInit = TRUE;

	g_ImgAnaly.SetHwnd(eAnalyWindow_Ref,m_pWnd1->m_hWnd );
	g_ImgAnaly.SetHwnd(eAnalyWindow_Sap,m_pWnd0->m_hWnd );
	g_ImgAnaly.SetHwnd(eAnalyWindow_Adj,m_pWnd2->m_hWnd );
	g_ImgAnaly.SetHwnd(eAnalyWindow_Sub,m_pWnd3->m_hWnd );

	return 0;
}

int CCheckView::InitCheckView()
{
	int nRet = -1;
	do 
	{
		int cx,cy;
		nRet = g_ImgAnaly.GetImageSize(cx,cy);
		if( DD_ERR_SUCCESS != nRet )
		{
			break;
		}
		if( 0 == cx || 0 == cy )
		{
			break;
		}

		float f1,f2;

		int x,y;
		CRect rtClient;
		GetClientRect(&rtClient);
		x = rtClient.right/2;
		y = rtClient.bottom/2;

		f1 = x;
		f1 /= cx;

		f2 = y;
		f2 /= cy;

		if( f1 > f2 )
		{
			f1 = f2;
		}

		zkImgDraw xImgDraw;
		xImgDraw.nScrollx    = 0;
		xImgDraw.nScrolly    = 0;
		xImgDraw.fZoomFactor = f1;

		g_ImgAnaly.Draw(eAnalyWindow_Sap, &xImgDraw);

	} while (false);

	return 0;
}

